/**
 * api驗證類
 * 
 */
function apiVerify() {
	var _fog = new loadDB("fog");
	var _sql = "update fog_api_users_verify set verify_time='2010-02-05 09:20:54' where ip = '127.0.0.1'";
	//_fog.execute(_sql);
	//登陸會員隊列
	this.login_user = [];	
	//api初始判斷
	this.init = function() {
		__api_verify = null;
		if ( __api_verify == null) {		
			this.verify();
		}else if (__api_verify['time'] < getTimer() ) {
			this.verify();
		}
	}
	//api初始方法
	this.verify = function() {
		var _send = new LoadVars();
		var _load = new LoadVars();
		_load.onLoad = this.verifyKey;		
		_send.sendAndLoad(API_URL, _load, 'get');
	}
	//取得臨時密鑰驗證
	this.verifyKey = function(r_ok,r_err) {
		if ( r_ok ) {					
		var _res = stringToObject(this.res);		
		if ( _res.number != 1 ) {
			//trace(_res.result);
			var _verify = _server.md5(String(API_KEY) + String(_res.result));
			//__log.show(_res);
			if (_res.number == 0) {
				var _time = getTimer() + API_TIMEOUT * 1000;			
				__api_verify = {time:_time};
				__api.login();
			}else{
				var _load_new = new LoadVars();
				var _send_new = new LoadVars();
				var _url = API_URL;
				_send_new.api_accounts = API_ACCOUNTS;
				_send_new.api_key = _verify;
				_url += "&accounts=" + API_USER;
				_url += "&password=" + API_PASS;
				_load_new.onLoad = function(r_ok, r_err) {				
					if ( r_ok ) {
						var _res = stringToObject(this.res);
						if ( _res['number'] == 1 ) {						
							var _time = getTimer() + API_TIMEOUT*1000;			
							__api_verify = {time:_time};
							//trace("api reged success And after " + API_TIMEOUT + "'s later will be out!");	
							__api.login();
						}else {
							__api_verify = null;
							var _verify = _server.md5(String(API_KEY) + String(_res.result));
							__log.show(_res);
							trace("key=" + _verify);
							}
						}				
				};			
				_send_new.sendAndLoad(_url, _load_new, 'post');			
			}
		}else {
			trace("the result of the php return is a wrony style");
			}			
		}else {
			trace("The URL Of Api Is Error!");
		}	
	}	
	//登陸會員隊列
	this.login = function() {
		__log.show("api checked success");
		if ( this.login_user.length > 0 ) {			
			for each(var _login in this.login_user) {				
				var _send = new LoadVars();
				var _load = new LoadVars();
				_load.name = _login.name;
				_load.pass = _login.pass;
				_load.user = _login.user;
				_load.onLoad = _login.loginResult;
				var _url = API_URL;
				_url += "&accounts=" + _login.name;
				_url += "&password=" + _login.pass;
				_send.sendAndLoad(_url, _load, 'get');				
			}
			this.login_user = [];
		}
	}
}